package com.atguigu.realtime.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/4/27 11:15
 */
public class MyKeyWordUtil {
    // 小米手机 -> [小米, 手机]
    public static Set<String> analyzer(String text) {
        StringReader reader = new StringReader(text);
        
        IKSegmenter ik = new IKSegmenter(reader, true);
        Set<String> words = new HashSet<>();
        try {
            Lexeme next = ik.next();
            while(next != null){
                String word = next.getLexemeText();
                words.add(word);
                next = ik.next();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return words;
    }
    
    public static void main(String[] args) throws IOException {
        System.out.println(analyzer("手机 小米手机"));
    }
}
